<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if(!isset($_SESSION['member_id']))
    echo"<script type='text/javascript'>top.window.location='index.php';</script>";
if(isset($_SESSION['lang']))
    require_once "./language_files/availableConferences2_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/availableConferences2_en.php";
if(!isset($_SESSION['member_id']))
    echo "<script>top.window.location='index.php'</script>";
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <title>Available Conferences</title>
    </head>
    <body>
        <button class="new_conference padding"><?php echo $lang['button_name_4'];?></button>
        <table>
            <tr>
                <td colspan="2" class="paging_col">
                </td>
                <td colspan="2" style="text-align: right;">
                    <input type="checkbox" style="outline: 2px solid green" disabled="disabled"/> <?php echo $lang['not_subscribed'];?>
                    <input type="checkbox" style="outline: 2px solid red" disabled="disabled"/> <?php echo $lang['subscribed'];?>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="check_uncheck" class="check_uncheck" id="check_uncheck"/><label style="cursor: pointer;" for="check_uncheck"><?php echo $lang['check'];?></label>
                    <button class="subscribe"><?php echo $lang['button_name_1'];?></button>
                </td>
                <?php
                require_once 'statics.php';
                $rsExpertise=rsSelect("*","area_of_expertise");
                if(is_string($rsExpertise))
                    echo $rsExpertise;
                else
                {
                    ?>
                    <td><label><?php echo $lang['filter_2'];?></label>
                        <?php
                        $rsPlaces=rsSelect("*","country",NULL,"ORDER BY country_name");
                        if(is_string($rsPlaces))
                            echo $rsPlaces;
                        else
                        {
                            echo "<select class='place'>
                            <optgroup label='Places'>
                            <option value='All'>All</option>";
                            while($row=mysql_fetch_assoc($rsPlaces))
                            {
                                echo "<option value='{$row['country_id']}'>{$row['country_name']}</option>";
                            }
                            echo "</optgroup></select></td>";
                        }
                        ?>
                        <td><label><?php echo $lang['filter_1'];?></label><select class='expertise'>
                                <optgroup label='Choose area'>
                                    <option value='0'>All</option>
                                    <?php
                                    while($row=mysql_fetch_assoc($rsExpertise))
                                    {
                                        echo "<option value='{$row['area_of_expertise_id']}'>{$row['area_of_expertise_text']}</option>";
                                    }
                                    echo "</optgroup></select></td>";
                                }
                                ?>
                                <td>
                                    <label><?php echo $lang['display'];?></label><select class="paging">
                                        <optgroup label="Paging">
                                            <option value="All">All</option>
                                            <option value="5">5</option>
                                            <option value="10" selected="selected">10</option>
                                            <option value="30">30</option>
                                            <option value="50">50</option>
                                            <option value="100">100</option>
                                        </optgroup>
                                    </select>
                                </td>
                                </tr>
                                <tr id="titles">
                                    <td style="white-space: nowrap;background-color:#003366;color:white;"><strong style="padding: 5px;"><?php echo $lang['conference'];?></strong><img style="background-color: #003366;display:inline;vertical-align: middle;" class="alphabetical" src="down.png"></img></td>
                                    <td style="white-space: nowrap;background-color:#003366;color:white;"><strong style="padding: 5px;"><?php echo $lang['place'];?></strong></td>
                                    <td style="white-space: nowrap;background-color:#003366;color:white;"><strong style="padding: 5px;"><?php echo $lang['area_of_expertise'];?></strong></td>
                                    <td style="white-space: nowrap;background-color:#003366;color:white;"><strong style="padding: 5px;"><?php echo $lang['conference_date'].' YYYY-MM-DD';?></strong><img style="background-color: #003366;display:inline;vertical-align: middle;" class="date" src="down.png"></img></td>
                                </tr>
                                <tr class="conference_row">
                                    <td><img src="main-loader.gif" alt="loading..." align="center" /> </td>
                                </tr>
                                <?php
                                if(is_string($rsExpertise))
                                    echo $rsExpertise;
                                else
                                {
                                    mysql_data_seek($rsExpertise,0);
                                    echo "<tr class='lower_set'><td>
                       <input type='checkbox' name='check_uncheck' class='check_uncheck' id='check_uncheck'/><label style='cursor:pointer;' for='check_uncheck'>" . $lang['check'] . "</label>
                        <button class='subscribe'>" . $lang['button_name_1'] . "</button>
                        </td>";
                                    echo"<td><label>" . $lang['filter_2'] . "</label>";
                                    mysql_data_seek($rsPlaces,0);
                                    if(is_string($rsPlaces))
                                        echo $rsPlaces;
                                    else
                                    {
                                        echo "<select class='place'>
                            <optgroup label='Places'>
                            <option value='All'>All</option>";
                                        while($row=mysql_fetch_assoc($rsPlaces))
                                        {
                                            echo "<option value='{$row['country_id']}'>{$row['country_name']}</option>";
                                        }
                                        echo "</optgroup></select></td>";
                                    }
                                    echo"<td>
                        <label>" . $lang['filter_1'] . "</label><select class='expertise'>
                        <optgroup label='Choose area'>
                        <option value='0'>All</option>";
                                    while($row=mysql_fetch_assoc($rsExpertise))
                                    {
                                        echo "<option value='{$row['area_of_expertise_id']}'>{$row['area_of_expertise_text']}</option>";
                                    }
                                    echo "</optgroup></select></td>";
                                    echo "<td>
                            <label>Display per page</label>
                            <select class='paging'>
                            <optgroup label='Paging'>
                            <option value='All'>All</option>
                            <option value='5'>5</option>
                            <option value='10' selected='selected'>10</option>
                            <option value='30'>30</option>
                            <option value='50'>50</option>
                            <option value='100'>100</option>
                            </optgroup>
                            </select>
                       </td></tr>";
                                    echo"<tr class='lower_set'>
                       <td colspan='2' class='paging_col'>
                       </td>
                       <td colspan='2' style='text-align: right;'>
                            <input type='checkbox' style='outline: 2px solid green' disabled='disabled'/> " . $lang['not_subscribed'] . "
                            <input type='checkbox' style='outline: 2px solid red' disabled='disabled'/> " . $lang['subscribed'] . "
                      </td>
                    </tr>";
                                }
                                ?>
                                </table><br/>
                                <button class="new_conference padding"><?php echo $lang['button_name_4'];?></button>
                                <?php require_once "jquery.php";?>
                                <script type="text/javascript" src="functions.js"></script>
                                <script type="text/javascript">
                                    //<![CDATA[
                                    function fetch()
                                    {
                                        $(".conference_row").remove();
                                        $("#titles").after("<tr class='conference_row'><td class='no_border' colspan='10'><p align='center'><img src='main-loader.gif' alt='loading...' align='center' /></p></td></tr>");
                                        $.ajax({
                                            type: "POST",
                                            url: "availableConferencesServer.php",
                                            data:{paging:perpage,limit:limit_start,alpha:alphabetical,date:bydate,filter_expertise:expertise,filter_place:place},
                                            success: function(response)
                                            {
                                                $(".conference_row").remove();
                                                $(".check_uncheck").removeAttr("checked");
                                                formatted=response.split("%%EOR%%");
                                                if(formatted.length==2)
                                                {
                                                    total=parseInt(formatted[0]);
                                                    if(total>10)
                                                        $(".lower_set").show();
                                                    else
                                                        $(".lower_set").hide();
                                                    if(total==0)
                                                        $("#titles").after("<tr class='conference_row'><td colspan='4'>No results were found matching your criteria</td></tr>")
                                                    $(".paging_col").html("");
                                                    if(perpage!="All")
                                                    {
                                                        if(total>parseInt(perpage))
                                                        {
                                                            num_pages=Math.ceil(total/perpage);
                                                            num=1;
                                                            start=0;
                                                            while(num%10!=0)
                                                            {
                                                                if(num<=num_pages)
                                                                {
                                                                    $(".paging_col").append("<a class='page_numbers' start='"+start+"' href='#'>"+num+"</a> ");
                                                                    num++;
                                                                    start+=parseInt(perpage);
                                                                }
                                                                else
                                                                    break;
                                                            }
                                                            if(num_pages>10)
                                                            {
                                                                start+=parseInt(perpage);
                                                                $(".paging_col").append("<a class='next_set' num='"+num+"' start='"+start+"' href='#'>>></a>");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            $(".paging_col").append("<a class='page_numbers' start='0' href='#'>1</a>");
                                                        }
                                                    }
                                                    $(".page_numbers").each(function()
                                                    {
                                                        if($(this).html()==current_page)
                                                            $(this).css("border", "1px dashed");
                                                    });
                                                    $("#titles").after(formatted[1]);
                                                    bind();
                                                    resize_iframe();
                                                }
                                            }
                                        });
                                    }
                                    function bind()
                                    {
                                        $(".next_set").bind("click", function()
                                        {
                                            num=parseInt($(this).attr("num"));
                                            start=parseInt($(this).attr("start"));
                                            $(".paging_col").html("");
                                            if(num>10)
                                            {
                                                old_num=num-10;
                                                old_start=start-(perpage*10);
                                                $(".paging_col").append("<a class='next_set' num='"+old_num+"' start='"+old_start+"' href='#'>>></a>")
                                            }
                                            while(num%10!=0)
                                            {
                                                if(num<=num_pages)
                                                {
                                                    $(".paging_col").append("<a class='next_set' num='"+num+"' start='"+start+"' href='#'>>></a>");
                                                    start+=parseInt(perpage);
                                                    num++;
                                                }
                                                else
                                                    break;
                                            }
                                            if(total-start>perpage)
                                            {
                                                $(".paging_col").append("<a class='next_set' num='"+num+"' start='"+start+"' href='#'>>></a>");
                                            }
                                        });
                                        $(".page_numbers").bind("click",function(event)
                                        {
                                            event.preventDefault();
                                            if(current_page!=$(this).html())
                                            {
                                                limit_start=$(this).attr("start");
                                                current_page=$(this).html();
                                                fetch();
                                            }
                                            return false;
                                        });
                                        $(".conference_row td").bind("mouseenter",function()
                                        {
                                            $(this).parent("tr").find("td").css("background-color", "#003366");
                                            $(this).parent("tr").find("td,a").css("color", "white");
                                        });
                                        $(".conference_row td").bind("mouseleave",function()
                                        {
                                            $(this).parent("tr").find("td").css("background-color", "white");
                                            $(this).parent("tr").find("td,a").css("color", "#003366");
                                        });
                                    }
                                    //]]>
                                </script>
                                <script type="text/javascript">
                                    //<![CDATA[
                                    $(document).ready(function()
                                    {
                                        check_top();
                                        alphabetical=false;
                                        bydate=false;
                                        expertise="0";
                                        place="All";
                                        perpage="10";
                                        limit_start=0;
                                        current_page=1;
                                        $(".check_uncheck").bind("change",function()
                                        {
                                            if($(this).is(":checked"))
                                            {
                                                $(".conference_box").each(function()
                                                {
                                                    if($(this).attr("disabled")!="disabled")
                                                        $(this).attr("checked", "checked");
                                                });
                                                $(".check_uncheck").attr("checked", true);
                                            }
                                            else
                                            {
                                                $(".conference_box").attr("checked",false);
                                                $(".check_uncheck").attr("checked", false);
                                            }
                                        });

                                        $(".expertise").bind("change", function()
                                        {
                                            expertise=$(this).val();
                                            $(".expertise option[value="+$(this).val()+"]").attr("selected", "selected");
                                            current_page=1;
                                            limit_start=0;
                                            fetch();
                                        });
                                        $(".place").bind("change",function()
                                        {
                                            place=$(this).val();
                                            $(".place option[value="+$(this).val()+"]").attr("selected", "selected");
                                            current_page=1;
                                            limit_start=0;
                                            fetch();
                                        });
                                        $(".paging").bind("change",function()
                                        {
                                            perpage=$(this).val();
                                            $(".paging option[value="+$(this).val()+"]").attr("selected", "selected");
                                            current_page=1;
                                            limit_start=0;
                                            fetch();
                                        });
                                        $(".alphabetical").bind("click",function()
                                        {
                                            if(!alphabetical)
                                            {
                                                $(".alphabetical").css("outline", "2px solid green");
                                                $(".date").css("outline", "");
                                                alphabetical=true;
                                                bydate=false;
                                                current_page=1;
                                                limit_start=0;
                                                fetch();
                                            }
                                        });
                                        $(".date").bind("click",function()
                                        {
                                            if(!bydate)
                                            {
                                                $(".date").css("outline", "2px solid green");
                                                $(".alphabetical").css("outline", "");
                                                bydate=true;
                                                alphabetical=false;
                                                current_page=1;
                                                limit_start=0;
                                                fetch();
                                            }
                                        });
                                        $(".new_conference").bind("click",function()
                                        {
                                            element=top.document.getElementById("collabsoft");
                                            $(element).attr("src", "conferenceSetup.php");
                                        });
                                        $(".subscribe").bind("click",function()
                                        {
                                            selected_confs=[];
                                            if($("input[name='conferences[]']:checked").length>0)
                                            {
                                                $("input[name='conferences[]']:checked").each(function()
                                                {
                                                    selected_confs[selected_confs.length]=$(this).val();
                                                });
                                                $.ajax({
                                                    type:"POST",
                                                    url:"availableConferencesServer.php",
                                                    data:{subscribe:1,conf_ids:selected_confs},
                                                    success:function(response)
                                                    {
                                                        if(response=="1")
                                                        {
                                                            fetch();
                                                        }
                                                        else if(response=="0")
                                                            alert("An error has occured during subscription please try again later");
                                                        else
                                                            alert(response);
                                                    }
                                                });
                                            }
                                            else
                                                alert("please select at least one conference");
                                        });
                                        fetch();
                                    });
                                    //]]>
                                </script>
                                </body>
                                </html>